/**
 * Created by d on 2017/5/17.
 */


var config = {

    'url':'http://www.f.com/',
    'token': '123',
    'error': '请求失败!',
    'default_success':'loading!',
    'success':''
};
$.config = {
    autoInit: true //no recommend
};
var pageId = ['login','order_list'];

var ajax = function (url,data,callback,message) {
    url = config.url + url;

    //定义message
    message = arguments.length > 3 ? message : config.default_success;

    var result = false;
    $.ajax({
        type: "post",
        data: data,
        url: url,
        async: true,
        dataType: "json",
        beforeSend: function () {
             //ajax请求之前
            $.showPreloader(message);
        },
        complete: function (XMLHttpRequest, textStatus) {
            //
            if (textStatus != 'success'){
                $.toast(config.error);
            } else {
                $.hidePreloader();
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrow) {
             //ajax请求失败
            if (textStatus == 'error')
            {
                $.toast(config.error);
            }
        },
        success:callback
    });
};
